﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EncomiendaMVC.Metadata;
using System.Web.UI;
using System.IO;

namespace EncomiendaMVC.Helpers
{
    public static class UtilHelper
    {
        public static string LimitarTexto(this HtmlHelper helper, string texto)
        { 
            
            return texto.Length>4? texto.Substring(0,4) + "..." : texto;
        }

        public static string Localizar(
            this HtmlHelper helper,
            string codigo, string tipoRecurso)
        {
            return RecursoUtil.ObtenerMensaje(codigo, tipoRecurso);
        }

        public static HtmlString Titulo(
            this HtmlHelper htmlHelper,
            string titulo)
        {
            var writer = new HtmlTextWriter(new StringWriter());
            writer.RenderBeginTag("div");
            writer.RenderBeginTag("h2");
            writer.Write(titulo);
            writer.RenderEndTag();
            //writer.RenderBeginTag("p");
            //writer.Write(contenido);
            //writer.RenderEndTag();
            writer.RenderEndTag();
            return new HtmlString(writer.InnerWriter.ToString());
        }

        public static MvcHtmlString Header(this HtmlHelper helper, string content)
        {
            var tagBuilder = new TagBuilder("header");
            tagBuilder.InnerHtml = content;
            return new MvcHtmlString(tagBuilder.ToString());
        }
    }
}
